package cn.imvc.app.controllers.member;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import cn.imvc.app.entities.Dealer;
import cn.imvc.app.entities.DealerLevel;
import cn.imvc.app.models.DealerLevelModel;
import cn.imvc.app.models.DealerModel;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;
/**
 * 
 * @author wujxViewDealer.java
 * @time 2016年7月19日
 *
 */
public class DealerControllerImpl implements DealerController {
	static Logger logger = Logger.getLogger(DealerControllerImpl.class);
	private Page<Object []> page; 
	public ViewRequest viewRequest;
	
	private List<DealerLevel> dealerLevelList;
	private int id;
	@Autowired
	private DealerModel dealerModel;
	@Autowired
	private DealerLevelModel dealerLevelModel;
	private Dealer dealer;
	
	@Autowired
	LoggingModel loggingModel;
	public String search() {
		// TODO Auto-generated method stub
		return null;
	}

	public String index() {
		page = dealerModel.findAll(id,viewRequest);
		dealerLevelList = dealerLevelModel.findAll();
		return "dealer/index";
	}
	
	/**
	 * 分销商详情
	 */
	public String detail(){
		dealer = dealerModel.getOne(id);
		return "dealer/detail";
	}
	
	public String subDetail() {
		page = dealerModel.findAll(id,viewRequest);
		return "dealer/subDealer";
	}
	
	/**
	 * 升级为代理
	 */
	public String upgradeTopUI(){
		loggingModel.info(logger,"升级经销商："+id);
		dealer = dealerModel.getOne(id);
		dealerLevelList = dealerLevelModel.findByLevelGreaterThan(dealer.getDealerLevel().getLevel());
		
		return "dealer/upgradeTop";
	}
	public String upgradeTop(){
		loggingModel.info(logger,"升级经销商："+id);
		dealerModel.updateLevel(id,dealer);
		return Render.json(new DialogBean("200", "升级成功!","","closeCurrent"));
	}
	
	public String show() {
		// TODO Auto-generated method stub
		return null;
	}

	public String editNew() {
		// TODO Auto-generated method stub
		return null;
	}

	public String create() {
		// TODO Auto-generated method stub
		return null;
	}

	public String edit() {
		// TODO Auto-generated method stub
		return null;
	}

	public String update() {
		
		return null;
	}

	public String destroy() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroyBatch() {
		// TODO Auto-generated method stub
		return null;
	}


	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Dealer getDealer() {
		return dealer;
	}

	public void setDealer(Dealer dealer) {
		this.dealer = dealer;
	}

	public Page<Object[]> getPage() {
		return page;
	}

	public void setPage(Page<Object[]> page) {
		this.page = page;
	}

	public List<DealerLevel> getDealerLevelList() {
		return dealerLevelList;
	}

	public void setDealerLevelList(List<DealerLevel> dealerLevelList) {
		this.dealerLevelList = dealerLevelList;
	}

	
}
